package com.集合.HashSet;
import java.util.HashSet;
public class HashSetDemo {
    public static void main(String[] args) {
        HashSet<Student> hs = new HashSet<Student>();
        Student s1 = new Student("张三",20);
        Student s2 = new Student("李四",22);
        Student s3 = new Student("汤姆",15);
        Student s4 = new Student("张三",20);
        Student s5 = new Student("张三",24);
        /*  hashSet集合存储学生对象为保证数据唯一性，需要重写学生类的equals()方法
        * 和hashCode()方法，但没法避免同名异龄的情况*/
        hs.add(s1);
        hs.add(s2);
        hs.add(s3);
        hs.add(s4);
        hs.add(s5);
        System.out.println(hs);
        for(Student s:hs){
            System.out.println(s.getName()+", "+s.getAge());
        }
    }
}
